#ifndef __LIGHTCOMMON_H__
#define __LIGHTCOMMON_H__


typedef enum
{
	emit_point,
	emit_area,
	emit_spotlight,
	emit_sun
} emittype_t;

typedef struct light_s
{
	struct light_s *next;
	emittype_t	type;
	struct shaderInfo_s	*si;

	vec3_t		origin;
	vec3_t		normal;		// for surfaces, spotlights, and suns
	float		dist;		// plane location along normal

	qboolean	linearLight;
	int			photons;
	int			style;
	vec3_t		color;
	float		radiusByDist;	// for spotlights

	qboolean	twosided;		// fog lights both sides

	struct winding_s	*w;
	vec3_t		emitColor;		// full out-of-gamut value

	int			cluster;

	qboolean	realTime;
	qboolean	realTimeShadows;	// Valid even across obstacles
	qboolean	noGrid;				// Don't discharge to grid

	int			rtLightID;
} light_t;

typedef struct
{
	//vec3_t direction;
	//vec3_t ambient;
	//vec3_t directed;

	vec3_t shAmbient;
	vec3_t shDirectional[3];
	vec3_t shQuadratic[5];

	qboolean flat;
} lightcoef_t;


void SplitLightComponents(vec3_t lightDir, vec_t *averagedDir, vec3_t surfaceNormal, vec3_t baseColor, vec_t *ambient, vec_t *directed, float visibleArea);
void AccumulateDirection(float *currentDir, float weight, float *newDir, float *normal);
//qboolean LightContributionToPoint( const struct light_s *light, const vec3_t origin, vec3_t color, traceWork_t *tw );
void LightingAtSample(vec3_t origin, vec3_t normal,
					  lightcoef_t *lightCoef, 
					  qboolean testOcclusion, qboolean forceSunLight, struct light_s *forceLight, traceWork_t *tw);
int VL_CreateSunDirections(vec3_t *sunDirections, vec3_t baseDir, qboolean lores);

extern vec3_t *gridradiosity;
void CalcGridRadiosity();

//light_t		*lights;


extern light_t *lights;
extern light_t fakeSunLight;

extern double totalPhotons;
extern double objectivePhotons;

extern float radiosityScale;
extern float directScale;



void ContributeLight(float *lightDir, lightcoef_t *lightCoef, float *surfaceNormal, float *color, float visibleAreaScale, int passNum);
void LightCoefToLightmaps(const lightcoef_t *lightCoef, float *lightmaps);
void LightmapsToLightCoef(const float *lightmaps, lightcoef_t *lightCoef);

#define SH_ENABLED

#define WORLD_LIGHT_FACTOR	4.0f

#endif
